{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1、Create 请求成功200 返回空字符串\n",
    "> 在开始检测之前，我们需要构建一个列表用于装取我们需要进行对比的人脸\n",
    "- [创建人脸列表api文档](https://docs.microsoft.com/zh-cn/rest/api/cognitiveservices/face/facelist/create)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import requests\n",
    "import json\n",
    "# 1、create  列表\n",
    "# faceListId\n",
    "faceListId =  'zjy_111'#学生填写\n",
    "create_facelists_url =\"https://api-zjy.cognitiveservices.azure.com/face/v1.0/facelists/{}\" # URL（见API文档）\n",
    "subscription_key =\"c65518f36b614654bd06a8eb87a0942c\" #学生填写\n",
    "assert subscription_key\n",
    "\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}\n",
    "data = {\n",
    "    \"name\":\"api_facelist\",\n",
    "    \"userData\":\"相册集\",\n",
    "    \"recognitionMedol\":\"recognition_03\",\n",
    "# 学生填写    \n",
    "}\n",
    "params ={\n",
    "    \"faceListId\":\"zjy_111\"\n",
    "}\n",
    "\n",
    "r_create = requests.put(create_facelists_url.format(faceListId),headers=headers,params=params,json=data) \n",
    "r_create.status_code#学生填写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b''"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_create.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 已经成功创建facelist（云端/云计算）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2、Add face 请求成功200 返回persistedFaceId\n",
    "> 我们通过上面的步骤建好了一个脸的列表，接下来我们要给这个列表添加脸了！把我们想要对比的脸存进列表吧\n",
    "- [添加人脸进列表api文档](https://docs.microsoft.com/zh-cn/rest/api/cognitiveservices/face/facelist/addfacefromurl)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "#先加一张脸试试\n",
    "# 2、Add face\n",
    "add_face_url =  'https://api-zjy.cognitiveservices.azure.com/face/v1.0/facelists/zjy_111/persistedFaces'#学生填写\n",
    "\n",
    "assert subscription_key\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}\n",
    "img_url = 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3464021933,3034616676&fm=26&gp=0.jpg'#学生填写\n",
    "\n",
    "params_add_face={\n",
    "     \"faceListId\":\"zjy_111\",\n",
    "     \"userData\": \"相册集\"\n",
    "#学生填写\n",
    "}\n",
    "\n",
    "r_add_face = requests.post(add_face_url.format(faceListId),headers=headers,params=params_add_face,json={\"url\":img_url})#学生填写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_add_face.status_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'persistedFaceId': '498c6f39-d01a-41fc-aff1-016ae3165e3c'}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_add_face.json()#返回persistedFaceId"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 扩展内容，封装成函数方便多次使用 *\n",
    "> 我们要添加多张脸，但是为了减少代码量，我们可以把代码封装成函数，避免每次都要写一大堆代码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 封装成函数方便添加图片\n",
    "def AddFace(img_url=str,userData=str):\n",
    "    add_face_url =\"https://api-zjy.cognitiveservices.azure.com/face/v1.0/facelists/zjy_111/persistedFaces\"\n",
    "    assert subscription_key\n",
    "    headers = {\n",
    "        # Request headers\n",
    "        'Content-Type': 'application/json',\n",
    "        'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "    }\n",
    "    img_url = img_url\n",
    "\n",
    "    params_add_face={\n",
    "        \"userData\":userData\n",
    "    }\n",
    "    r_add_face = requests.post(add_face_url.format(faceListId),headers=headers,params=params_add_face,json={\"url\":img_url})\n",
    "    return r_add_face.status_code#返回出状态码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/Autumnhui.jpg\",\"丘天惠\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/L-Tony-info.jpg\",\"林嘉茵\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/TLINGP.jpg\",\"汤玲萍\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/WenYanZeng.jpg\",\"曾雯燕\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/XIEIC.jpg\",\"谢依希\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/YuecongYang.png\",\"杨悦聪\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/Zoezhouyu.jpg\",\"周雨\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/crayon-heimi.jpg\",\"刘瑜鹏\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/jiayichen.jpg\",\"陈嘉仪\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/kg2000.jpg\",\"徐旖芊\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/liuxinrujiayou.jpg\",\"刘心如\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/liuyu19.png\",\"刘宇\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/ltco.jpg\",\"李婷\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/lucaszy.jpg\",\"黄智毅\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/pingzi0211.jpg\",\"黄慧文\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/shmimy-cn.jpg\",\"张铭睿\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/yichenting.jpg\",\"陈婷\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/coco022.jpg\",\"洪可凡\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/lujizhi.png\",\"卢继志\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/zzlhyy.jpg\",\"张梓乐\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 附加：get查看facelists\n",
    "> 查看列表\n",
    "- [查看人脸列表api文档](https://docs.microsoft.com/zh-cn/rest/api/cognitiveservices/face/facelist/get)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'persistedFaces': [{'persistedFaceId': '498c6f39-d01a-41fc-aff1-016ae3165e3c',\n",
       "   'userData': '相册集'},\n",
       "  {'persistedFaceId': '1ea0ec14-a3f3-4ce2-8ec4-dd91f6927c42',\n",
       "   'userData': '丘天惠'},\n",
       "  {'persistedFaceId': '612f7e41-f876-4861-9edb-74e24f6e5520',\n",
       "   'userData': '林嘉茵'},\n",
       "  {'persistedFaceId': '92dd95b3-46a9-43ef-9e9a-646026865599',\n",
       "   'userData': '汤玲萍'},\n",
       "  {'persistedFaceId': 'eacfec63-81c4-49c7-a124-d7dd157a2b47',\n",
       "   'userData': '曾雯燕'},\n",
       "  {'persistedFaceId': 'ebd19228-1f8d-42d9-be58-175eae93290d',\n",
       "   'userData': '谢依希'},\n",
       "  {'persistedFaceId': '5ca8fcf3-3482-4fd2-ad05-90248bc7763a',\n",
       "   'userData': '杨悦聪'},\n",
       "  {'persistedFaceId': 'f5a6c89a-c335-49d2-b938-8787986c0cdd',\n",
       "   'userData': '周雨'},\n",
       "  {'persistedFaceId': '30d3df62-9bc8-4bed-95ba-ce3727bcb970',\n",
       "   'userData': '刘瑜鹏'},\n",
       "  {'persistedFaceId': '9bd0a611-0adb-4a15-87bd-bc38c7ff2530',\n",
       "   'userData': '陈嘉仪'},\n",
       "  {'persistedFaceId': 'bee6c06f-548d-415b-8cfb-384a09be51e1',\n",
       "   'userData': '徐旖芊'},\n",
       "  {'persistedFaceId': '982b939d-bb61-4c79-98f2-6127fde2014a',\n",
       "   'userData': '刘心如'},\n",
       "  {'persistedFaceId': '55a432a5-263f-46ea-9128-c409fc14d0e0',\n",
       "   'userData': '刘宇'},\n",
       "  {'persistedFaceId': '3256f9ca-d242-44f6-872e-ad6578aaa8fb',\n",
       "   'userData': '李婷'},\n",
       "  {'persistedFaceId': '73661e0c-26d0-47be-80dd-7c21ecab9d30',\n",
       "   'userData': '黄智毅'},\n",
       "  {'persistedFaceId': '92aee3a7-ca7e-4b7c-82f0-c51cbe8f46b0',\n",
       "   'userData': '黄慧文'},\n",
       "  {'persistedFaceId': '823fa183-e6d3-4a77-88e8-09c3023c9dae',\n",
       "   'userData': '张铭睿'},\n",
       "  {'persistedFaceId': '08750b27-bed3-44ae-aa5c-1b350e26a461',\n",
       "   'userData': '陈婷'},\n",
       "  {'persistedFaceId': 'c7e5f330-7af6-4553-9d0f-ec7187b56145',\n",
       "   'userData': '洪可凡'},\n",
       "  {'persistedFaceId': 'b3b94221-5f78-470d-b46d-ecd59b7998c8',\n",
       "   'userData': '卢继志'},\n",
       "  {'persistedFaceId': '8a2898f0-578b-4c1e-b082-e46d4e130711',\n",
       "   'userData': '张梓乐'}],\n",
       " 'faceListId': 'zjy_111',\n",
       " 'name': 'api_facelist',\n",
       " 'userData': '相册集'}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Get facelist\n",
    "get_facelist_url = \"https://api-zjy.cognitiveservices.azure.com/face/v1.0/facelists/{}\"\n",
    "r_get_facelist = requests.get(get_facelist_url.format(faceListId),headers=headers,params=data)#学生填写\n",
    "r_get_facelist.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3、Detect 准备 被检测人 人脸的id\n",
    "> 删除分为两种，一种为删除人脸ID，一种为删除人脸列表\n",
    "- [删除人脸列表api文档](https://docs.microsoft.com/zh-cn/rest/api/cognitiveservices/face/facelist/delete)\n",
    "- [删除人脸ID api文档](https://docs.microsoft.com/zh-cn/rest/api/cognitiveservices/face/facelist/deleteface)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "faceListId = \"zjy_111\" #删除人脸列表 # 学生填写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Detect face 删除列表内人脸id\n",
    "delete_face_url =\"https://api-zjy.cognitiveservices.azure.com/face/v1.0/facelists/zjy_111/persistedFaces/8a2898f0-578b-4c1e-b082-e46d4e130711\"#学生填写\n",
    "\n",
    "assert subscription_key\n",
    "persistedFaceId = r_add_face.json()[\"persistedFaceId\"]\n",
    "# 直接取上面获得的ID{'persistedFaceId': 'f18450d3-60d2-45f3-a69e-783574dc3ce8'} \n",
    "\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}\n",
    "\n",
    "# 注意requests请求为delete\n",
    "r_delete_face = requests.delete(delete_face_url.format(faceListId,persistedFaceId),headers=headers)#学生填写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_delete_face"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Detect face 删除列表内人脸列表\n",
    "delete_face_url =#学生填写\n",
    "assert subscription_key\n",
    "\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}\n",
    "\n",
    "# format内直接删除\n",
    "# 注意requests请求为delete\n",
    "r_delete_facelist = requests.delete()#学生填写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_delete_facelist"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4、Find similars 返回相似置信度\n",
    "- [监测人脸相似度api文档](https://docs.microsoft.com/zh-cn/rest/api/cognitiveservices/face/face/findsimilar)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'faceId': '1da845aa-0936-4147-82a3-a37621f43236',\n",
       "  'faceRectangle': {'top': 103, 'left': 177, 'width': 126, 'height': 126},\n",
       "  'faceAttributes': {'smile': 0.0,\n",
       "   'headPose': {'pitch': 21.3, 'roll': 9.6, 'yaw': -4.1},\n",
       "   'gender': 'female',\n",
       "   'age': 22.0,\n",
       "   'facialHair': {'moustache': 0.0, 'beard': 0.0, 'sideburns': 0.0},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.0,\n",
       "    'neutral': 0.992,\n",
       "    'sadness': 0.001,\n",
       "    'surprise': 0.007},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.13},\n",
       "   'exposure': {'exposureLevel': 'overExposure', 'value': 0.82},\n",
       "   'noise': {'noiseLevel': 'high', 'value': 0.7},\n",
       "   'makeup': {'eyeMakeup': True, 'lipMakeup': True},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.1,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 0.97},\n",
       "     {'color': 'brown', 'confidence': 0.73},\n",
       "     {'color': 'other', 'confidence': 0.54},\n",
       "     {'color': 'gray', 'confidence': 0.24},\n",
       "     {'color': 'blond', 'confidence': 0.16},\n",
       "     {'color': 'red', 'confidence': 0.15},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}}]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3、检测人脸的id\n",
    "# replace <My Endpoint String> with the string from your endpoint URL\n",
    "face_api_url = 'https://api-zjy.cognitiveservices.azure.com/face/v1.0/detect'\n",
    "\n",
    "# 请求正文\n",
    "image_url = 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3464021933,3034616676&fm=26&gp=0.jpg'\n",
    "\n",
    "headers = {'Ocp-Apim-Subscription-Key': subscription_key}\n",
    "\n",
    "# 请求参数\n",
    "params = {\n",
    "    'returnFaceId': 'true',\n",
    "    'returnFaceLandmarks': 'false',\n",
    "    # 选择model\n",
    "    'recognitionModel':'recognition_03',#此参数需与facelist参数一致\n",
    "    'detectionModel':'detection_01',\n",
    "    # 可选参数,请仔细阅读API文档\n",
    "    'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise',\n",
    "}\n",
    "\n",
    "response = requests.post(face_api_url, params=params,\n",
    "                         headers=headers, json={\"url\": image_url})\n",
    "# json.dumps 将json--->字符串\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "findsimilars_url = \"https://api-zjy.cognitiveservices.azure.com/face/v1.0/findsimilars\"\n",
    "# 请求正文 faceID需要先检测一张照片获取\n",
    "data_findsimilars = {\n",
    "    \"faceId\":\" 1da845aa-0936-4147-82a3-a37621f43236\", #取上方的faceID\n",
    "    \"faceListId\":\"zjy_111\",\n",
    "    \"maxNumOfCandidatesReturned\":10,\n",
    "    \"mode\": \"matchFace\" #matchPerson #一种为验证模式，一种为相似值模式\n",
    "   \n",
    "   }\n",
    "r_findsimilars = requests.post(findsimilars_url,headers=headers,json=data_findsimilars)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'persistedFaceId': '78f2eb76-0db7-4b9b-a46c-23c52661134a',\n",
       "  'confidence': 0.29269},\n",
       " {'persistedFaceId': '297ae90b-9e11-4375-a6dc-f16c52446637',\n",
       "  'confidence': 0.20908},\n",
       " {'persistedFaceId': 'ddc744e3-583f-408d-b249-8aeac83b546d',\n",
       "  'confidence': 0.17849},\n",
       " {'persistedFaceId': '6be2eee6-1015-4741-9620-a2c3fa06aedb',\n",
       "  'confidence': 0.16209},\n",
       " {'persistedFaceId': 'fafb402e-3d0d-418b-9dec-da6ae893b677',\n",
       "  'confidence': 0.15023},\n",
       " {'persistedFaceId': 'd9855ce5-1ce9-4600-b18c-44066531618f',\n",
       "  'confidence': 0.101},\n",
       " {'persistedFaceId': '3d6de908-a09a-40d5-bd72-547517e3da17',\n",
       "  'confidence': 0.10034},\n",
       " {'persistedFaceId': 'bbf65461-1e33-4ec3-9fe7-e7de4539e4db',\n",
       "  'confidence': 0.0999},\n",
       " {'persistedFaceId': '9ff39ef7-ecb4-455b-8523-5398d0c8ec31',\n",
       "  'confidence': 0.09955},\n",
       " {'persistedFaceId': '83a0fc70-314a-4905-927b-6b9f7d5ac0a5',\n",
       "  'confidence': 0.09503}]"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_findsimilars.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>userData</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>9ff39ef7-ecb4-455b-8523-5398d0c8ec31</td>\n",
       "      <td>丘某峰</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>c5779143-83ff-4478-b5ad-8c78faae9fb8</td>\n",
       "      <td>丘天惠</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3d6de908-a09a-40d5-bd72-547517e3da17</td>\n",
       "      <td>林嘉茵</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>c8449aa8-0372-4af9-964c-9d2c9d7f4f2a</td>\n",
       "      <td>汤玲萍</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>b21fbea3-6b7b-4316-8e21-eeee6ca95a15</td>\n",
       "      <td>曾雯燕</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>bde75ba4-c85a-4c0d-9e21-5642eb528171</td>\n",
       "      <td>谢依希</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>3759e84e-b5a2-4a13-874a-e1f69beb98e1</td>\n",
       "      <td>杨悦聪</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>91a524ee-aa27-4107-8b23-988390608ac2</td>\n",
       "      <td>周雨</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>10a6049c-5a7c-4e7c-9d2b-f700f70bb6cc</td>\n",
       "      <td>刘瑜鹏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>6be2eee6-1015-4741-9620-a2c3fa06aedb</td>\n",
       "      <td>陈嘉仪</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>78f2eb76-0db7-4b9b-a46c-23c52661134a</td>\n",
       "      <td>徐旖芊</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>fafb402e-3d0d-418b-9dec-da6ae893b677</td>\n",
       "      <td>刘心如</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>89fc8cb1-ce61-4b2b-a737-2cb2cf7c6d78</td>\n",
       "      <td>刘宇</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>297ae90b-9e11-4375-a6dc-f16c52446637</td>\n",
       "      <td>李婷</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>83a0fc70-314a-4905-927b-6b9f7d5ac0a5</td>\n",
       "      <td>黄智毅</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>8b2189ee-cf34-4f96-a07d-a32a5f7d6e0b</td>\n",
       "      <td>黄慧文</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>ddc744e3-583f-408d-b249-8aeac83b546d</td>\n",
       "      <td>张铭睿</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>86897f4e-b017-480e-97a6-23195a31261d</td>\n",
       "      <td>陈婷</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>d9855ce5-1ce9-4600-b18c-44066531618f</td>\n",
       "      <td>洪可凡</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>7ea8a891-04de-4897-b354-490afad612a9</td>\n",
       "      <td>卢继志</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>bbf65461-1e33-4ec3-9fe7-e7de4539e4db</td>\n",
       "      <td>张梓乐</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         persistedFaceId userData\n",
       "0   9ff39ef7-ecb4-455b-8523-5398d0c8ec31      丘某峰\n",
       "1   c5779143-83ff-4478-b5ad-8c78faae9fb8      丘天惠\n",
       "2   3d6de908-a09a-40d5-bd72-547517e3da17      林嘉茵\n",
       "3   c8449aa8-0372-4af9-964c-9d2c9d7f4f2a      汤玲萍\n",
       "4   b21fbea3-6b7b-4316-8e21-eeee6ca95a15      曾雯燕\n",
       "5   bde75ba4-c85a-4c0d-9e21-5642eb528171      谢依希\n",
       "6   3759e84e-b5a2-4a13-874a-e1f69beb98e1      杨悦聪\n",
       "7   91a524ee-aa27-4107-8b23-988390608ac2       周雨\n",
       "8   10a6049c-5a7c-4e7c-9d2b-f700f70bb6cc      刘瑜鹏\n",
       "9   6be2eee6-1015-4741-9620-a2c3fa06aedb      陈嘉仪\n",
       "10  78f2eb76-0db7-4b9b-a46c-23c52661134a      徐旖芊\n",
       "11  fafb402e-3d0d-418b-9dec-da6ae893b677      刘心如\n",
       "12  89fc8cb1-ce61-4b2b-a737-2cb2cf7c6d78       刘宇\n",
       "13  297ae90b-9e11-4375-a6dc-f16c52446637       李婷\n",
       "14  83a0fc70-314a-4905-927b-6b9f7d5ac0a5      黄智毅\n",
       "15  8b2189ee-cf34-4f96-a07d-a32a5f7d6e0b      黄慧文\n",
       "16  ddc744e3-583f-408d-b249-8aeac83b546d      张铭睿\n",
       "17  86897f4e-b017-480e-97a6-23195a31261d       陈婷\n",
       "18  d9855ce5-1ce9-4600-b18c-44066531618f      洪可凡\n",
       "19  7ea8a891-04de-4897-b354-490afad612a9      卢继志\n",
       "20  bbf65461-1e33-4ec3-9fe7-e7de4539e4db      张梓乐"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#facelist里面的数据\n",
    "adf = pd.json_normalize(r_get_facelist.json()[\"persistedFaces\"])# 升级pandas才能运行\n",
    "adf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>confidence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>78f2eb76-0db7-4b9b-a46c-23c52661134a</td>\n",
       "      <td>0.29269</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>297ae90b-9e11-4375-a6dc-f16c52446637</td>\n",
       "      <td>0.20908</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ddc744e3-583f-408d-b249-8aeac83b546d</td>\n",
       "      <td>0.17849</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>6be2eee6-1015-4741-9620-a2c3fa06aedb</td>\n",
       "      <td>0.16209</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>fafb402e-3d0d-418b-9dec-da6ae893b677</td>\n",
       "      <td>0.15023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>d9855ce5-1ce9-4600-b18c-44066531618f</td>\n",
       "      <td>0.10100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>3d6de908-a09a-40d5-bd72-547517e3da17</td>\n",
       "      <td>0.10034</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>bbf65461-1e33-4ec3-9fe7-e7de4539e4db</td>\n",
       "      <td>0.09990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9ff39ef7-ecb4-455b-8523-5398d0c8ec31</td>\n",
       "      <td>0.09955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>83a0fc70-314a-4905-927b-6b9f7d5ac0a5</td>\n",
       "      <td>0.09503</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        persistedFaceId  confidence\n",
       "0  78f2eb76-0db7-4b9b-a46c-23c52661134a     0.29269\n",
       "1  297ae90b-9e11-4375-a6dc-f16c52446637     0.20908\n",
       "2  ddc744e3-583f-408d-b249-8aeac83b546d     0.17849\n",
       "3  6be2eee6-1015-4741-9620-a2c3fa06aedb     0.16209\n",
       "4  fafb402e-3d0d-418b-9dec-da6ae893b677     0.15023\n",
       "5  d9855ce5-1ce9-4600-b18c-44066531618f     0.10100\n",
       "6  3d6de908-a09a-40d5-bd72-547517e3da17     0.10034\n",
       "7  bbf65461-1e33-4ec3-9fe7-e7de4539e4db     0.09990\n",
       "8  9ff39ef7-ecb4-455b-8523-5398d0c8ec31     0.09955\n",
       "9  83a0fc70-314a-4905-927b-6b9f7d5ac0a5     0.09503"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 返回相似度的数据\n",
    "bdf = pd.json_normalize(r_findsimilars.json())# 升级pandas才能运行\n",
    "bdf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>userData</th>\n",
       "      <th>confidence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>78f2eb76-0db7-4b9b-a46c-23c52661134a</td>\n",
       "      <td>徐旖芊</td>\n",
       "      <td>0.29269</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>297ae90b-9e11-4375-a6dc-f16c52446637</td>\n",
       "      <td>李婷</td>\n",
       "      <td>0.20908</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>ddc744e3-583f-408d-b249-8aeac83b546d</td>\n",
       "      <td>张铭睿</td>\n",
       "      <td>0.17849</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>6be2eee6-1015-4741-9620-a2c3fa06aedb</td>\n",
       "      <td>陈嘉仪</td>\n",
       "      <td>0.16209</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>fafb402e-3d0d-418b-9dec-da6ae893b677</td>\n",
       "      <td>刘心如</td>\n",
       "      <td>0.15023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>d9855ce5-1ce9-4600-b18c-44066531618f</td>\n",
       "      <td>洪可凡</td>\n",
       "      <td>0.10100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3d6de908-a09a-40d5-bd72-547517e3da17</td>\n",
       "      <td>林嘉茵</td>\n",
       "      <td>0.10034</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>bbf65461-1e33-4ec3-9fe7-e7de4539e4db</td>\n",
       "      <td>张梓乐</td>\n",
       "      <td>0.09990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>9ff39ef7-ecb4-455b-8523-5398d0c8ec31</td>\n",
       "      <td>丘某峰</td>\n",
       "      <td>0.09955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>83a0fc70-314a-4905-927b-6b9f7d5ac0a5</td>\n",
       "      <td>黄智毅</td>\n",
       "      <td>0.09503</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        persistedFaceId userData  confidence\n",
       "3  78f2eb76-0db7-4b9b-a46c-23c52661134a      徐旖芊     0.29269\n",
       "5  297ae90b-9e11-4375-a6dc-f16c52446637       李婷     0.20908\n",
       "7  ddc744e3-583f-408d-b249-8aeac83b546d      张铭睿     0.17849\n",
       "2  6be2eee6-1015-4741-9620-a2c3fa06aedb      陈嘉仪     0.16209\n",
       "4  fafb402e-3d0d-418b-9dec-da6ae893b677      刘心如     0.15023\n",
       "8  d9855ce5-1ce9-4600-b18c-44066531618f      洪可凡     0.10100\n",
       "1  3d6de908-a09a-40d5-bd72-547517e3da17      林嘉茵     0.10034\n",
       "9  bbf65461-1e33-4ec3-9fe7-e7de4539e4db      张梓乐     0.09990\n",
       "0  9ff39ef7-ecb4-455b-8523-5398d0c8ec31      丘某峰     0.09955\n",
       "6  83a0fc70-314a-4905-927b-6b9f7d5ac0a5      黄智毅     0.09503"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#合并在一起，得出班级能谁最像你\n",
    "pd.merge(adf, bdf,how='inner', on='persistedFaceId').sort_values(by=\"confidence\",ascending = False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "301.992px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
